<template>
  <el-dialog
    v-el-drag-dialog
    title="远距配送费设置"
    :visible.sync="visible"
    width="1136px"
    @closed="reset"
  >
    <el-descriptions size="medium" border>
      <el-descriptions-item label="编码">{{
        temp.goodsCode
      }}</el-descriptions-item>
      <el-descriptions-item label="名称">{{
        temp.goodsName
      }}</el-descriptions-item>
      <el-descriptions-item label="类别">{{
        temp.gtName
      }}</el-descriptions-item>
    </el-descriptions>
    <div class="type-radio">
      <el-radio-group v-model="deliveryType">
        <el-radio :label="1">固定配送费用</el-radio>
        <el-radio :label="2">按距离设置配送费用</el-radio>
        <el-radio :label="3">按距离阶梯设置配送费用</el-radio>
      </el-radio-group>
    </div>
    <table v-if="deliveryType === 1" class="pure-table">
      <thead>
        <tr>
          <th />
          <th>基准值</th>
          <th>居民</th>
          <th>非居民</th>
          <th>工业</th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td style="width: 5rem;">配送费</td>
          <th>
            <el-input-number
              v-model="formData.fee0"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData.fee1"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData.fee2"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData.fee3"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
        </tr>
        <!-- <tr>
          <td>服务费</td>
          <th>
            <el-input-number
              v-model="formData.tpFee0"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData.tpFee1"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData.tpFee2"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData.tpFee3"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
        </tr> -->
      </tbody>
    </table>
    <table v-if="deliveryType === 3" class="tieredTable">
      <tbody>
        <tr>
          <td>居民用户</td>
          <td>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee29"
                disabled
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />公里至<el-input-number
                v-model="tieredFee.fee30"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee31"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee32"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(32)"
              />公里至<el-input-number
                v-model="tieredFee.fee33"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeEndChange(33)"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee34"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee35"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(35)"
              />公里至<el-input-number
                v-model="tieredFee.fee36"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeEndChange(36)"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee37"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离超过<el-input-number
                v-model="tieredFee.fee38"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(38)"
              />公里收取配送费<el-input-number
                v-model="tieredFee.fee39"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
          </td>
        </tr>
        <tr>
          <td>非居民用户</td>
          <td>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee40"
                disabled
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />公里至<el-input-number
                v-model="tieredFee.fee41"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee42"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee43"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(43)"
              />公里至<el-input-number
                v-model="tieredFee.fee44"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeEndChange(44)"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee45"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee46"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(46)"
              />公里至<el-input-number
                v-model="tieredFee.fee47"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeEndChange(47)"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee48"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离超过<el-input-number
                v-model="tieredFee.fee49"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(49)"
              />公里收取配送费<el-input-number
                v-model="tieredFee.fee50"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
          </td>
        </tr>
        <tr>
          <td>工业用户</td>
          <td>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee60"
                disabled
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />公里至<el-input-number
                v-model="tieredFee.fee51"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee52"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee53"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(53)"
              />公里至<el-input-number
                v-model="tieredFee.fee54"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeEndChange(54)"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee55"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离在<el-input-number
                v-model="tieredFee.fee56"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeChange(56)"
              />公里至<el-input-number
                v-model="tieredFee.fee57"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeEndChange(57)"
              />公里（包含）至收取配送费<el-input-number
                v-model="tieredFee.fee58"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
            <p>
              配送距离超过<el-input-number
                v-model="tieredFee.fee59"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
                @blur="feeEndChange(59)"
              />公里收取配送费<el-input-number
                v-model="tieredFee.fee61"
                :controls="false"
                :min="0"
                :max="10000"
                :precision="2"
              />元
            </p>
          </td>
        </tr>
      </tbody>
    </table>
    <table v-if="deliveryType === 2" class="pure-table">
      <thead>
        <tr>
          <th />
          <th>起步价(元)</th>
          <th>包含距离(公里)</th>
          <th>每增加(公里)</th>
          <th>增加金额(元)</th>
          <th>超出(公里)</th>
          <th>固定价格(元)</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td style="display: block; width: 100px;">居民用户</td>
          <th>
            <el-input-number
              v-model="formData2.fee4"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee5"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee6"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee7"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee8"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee9"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
        </tr>
        <tr>
          <td style="display: block; width: 100px;">工商用户</td>
          <th>
            <el-input-number
              v-model="formData2.fee10"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee11"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee12"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee13"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee14"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
          <th>
            <el-input-number
              v-model="formData2.fee15"
              :controls="false"
              :min="0"
              :max="10000"
              :precision="2"
              @blur="inputFormat"
            />
          </th>
        </tr>
      </tbody>
    </table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        关闭
      </el-button>
      <el-button
        :loading="$loadingPlugin.success"
        type="primary"
        @click="success"
      >
        保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { goodsDistributionServiceSave, distributionfeeEdit } from '@/api'
  export default {
    name: 'distributionDialog',
    data() {
      return {
        visible: false,
        org: null,
        temp: {},
        priceInfo: null,
        formData: {
          fee0: 0,
          fee1: 0,
          fee2: 0,
          fee3: 0
          // tpFee0: 0,
          // tpFee1: 0,
          // tpFee2: 0,
          // tpFee3: 0
        },
        formData2: {
          fee4: 0,
          fee5: 0,
          fee6: 0,
          fee7: 0,
          fee8: 0,
          fee9: 0,
          fee10: 0,
          fee11: 0,
          fee12: 0,
          fee13: 0,
          fee14: 0,
          fee15: 0
        },
        tieredFee: {
          fee29: 0,
          fee30: 0,
          fee31: 0,
          fee32: 0,
          fee33: 0,
          fee34: 0,
          fee35: 0,
          fee36: 0,
          fee37: 0,
          fee38: 0,
          fee39: 0,
          fee40: 0,
          fee41: 0,
          fee42: 0,
          fee43: 0,
          fee44: 0,
          fee45: 0,
          fee46: 0,
          fee47: 0,
          fee48: 0,
          fee49: 0,
          fee50: 0,
          fee51: 0,
          fee52: 0,
          fee53: 0,
          fee54: 0,
          fee55: 0,
          fee56: 0,
          fee57: 0,
          fee58: 0,
          fee59: 0,
          fee60: 0,
          fee61: 0
        },
        deliveryType: 1
      }
    },
    watch: {
      'tieredFee.fee30': function(val) {
        this.tieredFee.fee32 = val
        this.feeChange(32)
      },
      'tieredFee.fee33': function(val) {
        this.tieredFee.fee35 = val
        this.feeChange(35)
      },
      'tieredFee.fee36': function(val) {
        this.tieredFee.fee38 = val
      },
      'tieredFee.fee41': function(val) {
        this.tieredFee.fee43 = val
        this.feeChange(43)
      },
      'tieredFee.fee44': function(val) {
        this.tieredFee.fee46 = val
        this.feeChange(46)
      },
      'tieredFee.fee47': function(val) {
        this.tieredFee.fee49 = val
      },
      'tieredFee.fee51': function(val) {
        this.tieredFee.fee53 = val
        this.feeChange(53)
      },
      'tieredFee.fee54': function(val) {
        this.tieredFee.fee56 = val
        this.feeChange(56)
      },
      'tieredFee.fee57': function(val) {
        this.tieredFee.fee59 = val
      }
    },
    methods: {
      open(temp, org) {
        this.org = org
        this.getDefaultData(temp, org)
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) {
            this.temp = Object.assign(this.temp, temp)
            this.type = 'edit'
          }
        })
      },
      showTips() {

      },
      async getDefaultData(temp, org) {
        const res = await distributionfeeEdit({
          goodsId: temp.goodsId,
          orgId: org.orgId
        })
        console.log(res)
        const { fee0, fee1, fee2, fee3 } = res.data
        const { fee29, fee30, fee31, fee32, fee33, fee34, fee35, fee36, fee37, fee38, fee39, fee40, fee41, fee42, fee43,
                fee44, fee45, fee46, fee47, fee48, fee49, fee50, fee51, fee52, fee53, fee54, fee55, fee56, fee57, fee58,
                fee59, fee60, fee61, fee4, fee5, fee6, fee7, fee8, fee9, fee10, fee11, fee12, fee13, fee14, fee15 } = res.data
        this.formData = { fee0, fee1, fee2, fee3 }
        this.formData2 = { fee4, fee5, fee6, fee7, fee8, fee9, fee10, fee11, fee12, fee13, fee14, fee15 }
        this.tieredFee = { fee29, fee30, fee31, fee32, fee33, fee34, fee35, fee36, fee37, fee38, fee39, fee40, fee41, fee42, fee43,
                           fee44, fee45, fee46, fee47, fee48, fee49, fee50, fee51, fee52, fee53, fee54, fee55, fee56, fee57, fee58,
                           fee59, fee60, fee61 }
        this.deliveryType = Number(res.data.radioval)
        Object.keys(this.formData).forEach(item => {
          this.formData[item] = Number(this.formData[item])
        })
        Object.keys(this.tieredFee).forEach(item => {
          this.tieredFee[item] = Number(this.tieredFee[item])
        })
        console.log(this.formData, this.tieredFee)
        // this.priceInfo = JSON.parse(res.data.priceInfo)
        // if (this.priceInfo.fee0 & (0x01 > 0)) { this.$set(this.formData, 'fee0', (this.priceInfo.fee0 >> 1) * 0.01) }
        // if (this.priceInfo.fee1 & (0x01 > 0)) { this.$set(this.formData, 'fee1', (this.priceInfo.fee1 >> 1) * 0.01) }
        // if (this.priceInfo.fee2 & (0x01 > 0)) { this.$set(this.formData, 'fee2', (this.priceInfo.fee2 >> 1) * 0.01) }
        // if (this.priceInfo.fee3 & (0x01 > 0)) { this.$set(this.formData, 'fee3', (this.priceInfo.fee3 >> 1) * 0.01) }
        // if (this.priceInfo.tpFee0 & (0x01 > 0)) { this.$set(this.formData, 'tpFee0', (this.priceInfo.tpFee0 >> 1) * 0.01) }
        // if (this.priceInfo.tpFee1 & (0x01 > 0)) { this.$set(this.formData, 'tpFee1', (this.priceInfo.tpFee1 >> 1) * 0.01) }
        // if (this.priceInfo.tpFee2 & (0x01 > 0)) { this.$set(this.formData, 'tpFee2', (this.priceInfo.tpFee2 >> 1) * 0.01) }
        // if (this.priceInfo.tpFee3 & (0x01 > 0)) { this.$set(this.formData, 'tpFee3', (this.priceInfo.tpFee3 >> 1) * 0.01) }
      },
      async success() {
        const formData = JSON.parse(JSON.stringify(this.formData))
        const formData2 = JSON.parse(JSON.stringify(this.formData2))
        const tieredFee = JSON.parse(JSON.stringify(this.tieredFee))
        let json = {}
        if (this.deliveryType === 1) {
          if (!formData.fee0 && formData.fee0 !== 0) {
            this.$message.error('请输入远距配送费基准价')
            return
          }
          json = { ...formData }
          json.feetype = 1
        }
        if (this.deliveryType === 2) {
          if (formData2.fee4 || formData2.fee5 || formData2.fee6 || formData2.fee7 || formData2.fee8 || formData2.fee9) {
            if (!formData2.fee4 && formData2.fee4 !== 0) {
              this.$message.warning('居民用户起步价不能为空!')
              return
            }
            if (!formData2.fee5 && formData2.fee5 !== 0) {
              this.$message.warning('居民用户包含距离不能为空!')
              return
            }
            if (!formData2.fee6 && formData2.fee6 !== 0) {
              this.$message.warning('居民用户每增加(公里)不能为空!')
              return
            }
            if (!formData2.fee7 && formData2.fee7 !== 0) {
              this.$message.warning('居民用户增加金额不能为空!')
              return
            }
            if (!formData2.fee8 && formData2.fee8 !== 0) {
              this.$message.warning('居民用户超出(公里)不能为空!')
              return
            }
            if (!formData2.fee9 && formData2.fee9 !== 0) {
              this.$message.warning('居民用户固定价格不能为空!')
              return
            }
          }
          if (formData2.fee8) {
            formData2.fee8 = parseFloat(formData2.fee8)
            let fee5val = 0.0
            if (formData2.fee5) {
              formData2.fee5 = parseFloat(formData2.fee5)
              fee5val = formData2.fee5
            }
            if (formData2.fee6) {
              fee5val += parseFloat(formData2.fee6)
            }
            if (formData2.fee8 < fee5val) {
              this.$message.warning('居民用户超出公里应大于等于包含距离(公里)+每增加(公里)!')
              return
            }
          }
          if (formData2.fee10 || formData2.fee11 || formData2.fee12 || formData2.fee13 || formData2.fee14 || formData2.fee15) {
            if (!formData2.fee10 && formData2.fee10 !== 0) {
              this.$message.warning('工商用户起步价不能为空!')
              return
            }
            if (!formData2.fee11 && formData2.fee11 !== 0) {
              this.$message.warning('工商用户包含距离不能为空!')
              return
            }
            if (!formData2.fee12 && formData2.fee12 !== 0) {
              this.$message.warning('工商用户每增加(公里)不能为空!')
              return
            }
            if (!formData2.fee13 && formData2.fee13 !== 0) {
              this.$message.warning('工商用户增加金额不能为空!')
              return
            }
            if (!formData2.fee14 && formData2.fee14 !== 0) {
              this.$message.warning('工商用户超出(公里)不能为空!')
              return
            }
            if (!formData2.fee15 && formData2.fee15 !== 0) {
              this.$message.warning('工商用户固定价格不能为空!')
              return
            }
          }
          json = { ...formData2 }
          json.feetype = 2
        }
        if (this.deliveryType === 3) {
          let lessVerify1 = 0
          let lessVerifyOne = 0
          let lessVerify2 = 0
          let lessVerifyTwo = 0
          let lessVerify3 = 0
          let lessVerifyThree = 0
          const feeList1 = ['fee30', 'fee32', 'fee33', 'fee35', 'fee36', 'fee38']
          const feeList2 = ['fee41', 'fee43', 'fee44', 'fee46', 'fee47', 'fee49']
          const feeList3 = ['fee51', 'fee53', 'fee54', 'fee56', 'fee57', 'fee59']
          // 居民
          for (const item of feeList1) {
            //  统计为空
            if (this.tieredFee[item] === undefined) {
              lessVerify1++
            }
            //  统计为零
            if (this.tieredFee[item] === 0) {
              lessVerifyOne++
            }
          }
          // 有空不通过
          if (lessVerify1 > 0) {
            this.$message.error('居民用户配送距离不能为空!')
            return
          }
          // 要么全部为零要么全部不为零
          if (lessVerifyOne > 0 && lessVerifyOne < 6) {
            this.$message.error('居民用户非起始配送距离不能为零!')
            return
          }
          if (lessVerifyOne === 6) {
            tieredFee.fee31 = 0
            tieredFee.fee34 = 0
            tieredFee.fee37 = 0
            tieredFee.fee39 = 0
          }
          // 非居民
          for (const item of feeList2) {
            if (this.tieredFee[item] === undefined) {
              lessVerify2++
            }
            if (this.tieredFee[item] === 0) {
              lessVerifyTwo++
            }
          }
          if (lessVerify2 > 0) {
            this.$message.error('非居民用户配送距离不能为空!')
            return
          }
          if (lessVerifyTwo > 0 && lessVerifyTwo < 6) {
            this.$message.error('非居民用户非起始配送距离不能为零!')
            return
          }
          if (lessVerifyTwo === 6) {
            tieredFee.fee42 = 0
            tieredFee.fee45 = 0
            tieredFee.fee48 = 0
            tieredFee.fee50 = 0
          }
          // 工业
          for (const item of feeList3) {
            if (this.tieredFee[item] === undefined) {
              lessVerify3++
            }
            if (this.tieredFee[item] === 0) {
              lessVerifyThree++
            }
          }
          if (lessVerify3 > 0) {
            this.$message.error('工业用户配送距离不能为空!')
            return
          }
          if (lessVerifyThree > 0 && lessVerifyThree < 6) {
            this.$message.error('工业用户非起始配送距离不能为零!')
            return
          }
          if (lessVerifyThree === 6) {
            tieredFee.fee52 = 0
            tieredFee.fee55 = 0
            tieredFee.fee58 = 0
            tieredFee.fee61 = 0
          }
          // 下面判断有值的情况
          if ((this.tieredFee.fee32 === this.tieredFee.fee33 && this.tieredFee.fee32 !== 0) || (this.tieredFee.fee35 === this.tieredFee.fee36 && this.tieredFee.fee35 !== 0)) {
            this.$message.error('居民用户同档位结束值不应等于起始值!')
            return
          }
          if ((this.tieredFee.fee43 === this.tieredFee.fee44 && this.tieredFee.fee43 !== 0) || (this.tieredFee.fee46 === this.tieredFee.fee47 && this.tieredFee.fee46 !== 0)) {
            this.$message.error('非居民用户同档位结束值不应等于起始值!')
            return
          }
          if ((this.tieredFee.fee53 === this.tieredFee.fee54 && this.tieredFee.fee53 !== 0) || (this.tieredFee.fee56 === this.tieredFee.fee57 && this.tieredFee.fee56 !== 0)) {
            this.$message.error('工业用户同档位结束值不应等于起始值!')
            return
          }
          json = { ...tieredFee }
          json.feetype = 3
        }
        json.goodid = this.temp.goodsId
        json.orgid = this.org.orgId

        await goodsDistributionServiceSave({ json })
        this.resolve()
        this.visible = false
        this.$notify({
          title: '提示',
          message: '操作成功',
          type: 'success',
          duration: 2000
        })
      },

      async fixedDeliveryFee() {
        // const formData = JSON.parse(JSON.stringify(this.formData))

        // if (!formData.tpFee0 && formData.tpFee0 !== 0) {
        //   this.$message.error('请输入服务费基准价')
        //   return
        // }
        // formData.fee0 = this.amountHandle(formData.fee0)
        // formData.fee1 = this.amountHandle(formData.fee1)
        // formData.fee2 = this.amountHandle(formData.fee2)
        // formData.fee3 = this.amountHandle(formData.fee3)
        // formData.tpFee0 = this.amountHandle(formData.tpFee0)
        // formData.tpFee1 = this.amountHandle(formData.tpFee1)
        // formData.tpFee2 = this.amountHandle(formData.tpFee2)
        // formData.tpFee3 = this.amountHandle(formData.tpFee3)
        // const json = { ...formData }
        // json.goodsId = this.temp.goodsId
        // json.orgId = this.org.orgId
        // json.feetype = 1
        // await goodsDistributionServiceSave(json)
        // this.resolve()
        // this.visible = false
        // this.$notify({
        //   title: '提示',
        //   message: '操作成功',
        //   type: 'success',
        //   duration: 2000
        // })
      },

      amountHandle(e) {
        if (e === '' || e === 0) {
          return 0
        } else {
          e = e * 100
          return (e << 1) | 1
        }
      },
      inputFormat(e) {
        if (e.target.value) e.target.value = Number(e.target.value).toFixed(2)
      },
      reset() {
        this.type = 'add'
        this.deliveryType = 1
        this.formData = {
          fee0: 0,
          fee1: 0,
          fee2: 0,
          fee3: 0
        }
        this.tieredFee = {
          fee29: 0,
          fee30: 0,
          fee31: 0,
          fee32: 0,
          fee33: 0,
          fee34: 0,
          fee35: 0,
          fee36: 0,
          fee37: 0,
          fee38: 0,
          fee39: 0,
          fee40: 0,
          fee41: 0,
          fee42: 0,
          fee43: 0,
          fee44: 0,
          fee45: 0,
          fee46: 0,
          fee47: 0,
          fee48: 0,
          fee49: 0,
          fee50: 0,
          fee51: 0,
          fee52: 0,
          fee53: 0,
          fee54: 0,
          fee55: 0,
          fee56: 0,
          fee57: 0,
          fee58: 0,
          fee59: 0,
          fee60: 0,
          fee61: 0
        }
      },
      feeChange(val) {
        if (this.tieredFee[`fee${val + 1}`]) {
          if (this.tieredFee[`fee${val}`] > this.tieredFee[`fee${val + 1}`]) {
            this.$message.warning('结束值不应小于起始值')
            this.tieredFee[`fee${val + 1}`] = 0
            console.log(val)
          }
        }
        if (this.tieredFee[`fee${val - 2}`]) {
          this.tieredFee[`fee${val}`] = this.tieredFee[`fee${val - 2}`]
        }
      },
      feeEndChange(val) {
        if (this.tieredFee[`fee${val - 1}`]) {
          if (this.tieredFee[`fee${val}`] <= this.tieredFee[`fee${val - 1}`]) {
            this.$message.warning('结束值不应小于等于起始值')
            this.tieredFee[`fee${val}`] = 0
          }
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
table {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  border-spacing: 0;
}

td,
th {
  padding: 0;
}

.pure-table {
  border: 1px solid #cbcbcb;
  border-collapse: collapse;
  border-spacing: 0;
  empty-cells: show;
}

.pure-table caption {
  padding: 1em 0;
  color: #000;
  text-align: center;
}

.pure-table td,
.pure-table th {
  padding: 0.5em 1em;
  margin: 0;
  overflow: visible;
  line-height: 2rem;
  text-align: center;
  border-left: 1px solid #cbcbcb;
  border-width: 0 0 0 1px;
}

.pure-table thead {
  color: #000;
  text-align: left;
  vertical-align: bottom;
  background-color: #e5e7f2;
}

.pure-table td {
  background-color: transparent;
}

.pure-table-bordered td {
  border-bottom: 1px solid #cbcbcb;
}

.pure-table-bordered tbody > tr:last-child > td {
  border-bottom-width: 0;
}

.type-radio {
  padding: 10px 20px;
  margin-top: 10px;
  border: 1px solid #ebeef5;
}
.tieredTable {
  border-top: 1px solid #cbcbcb;
  border-left: 1px solid #cbcbcb;
  border-spacing: 0;
  empty-cells: show;
  td {
    padding: 0.5em 1em;
    border-right: 1px solid #cbcbcb;
    border-bottom: 1px solid #cbcbcb;
    p {
      line-height: 24px;
      /deep/ .el-input-number {
        width: 95px;
        height: 24px;
        margin: 0 4px;
        input {
          height: 24px;
        }
      }
    }
  }
  tr td:nth-child(1) {
    min-width: 85px;
  }
}
</style>
